import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'

declare type RouteRecordRawExt = RouteRecordRaw & { hidden?: boolean }

import Layout from '@/views/layout/index.vue'

const Home = () => import('@/views/Home.vue')
const nestedRouter = {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1/menu1-1',
    name: 'Nested',
    meta: {
        title: 'nested',
        icon: 'nested'
    },
    children: [
        {
            path: 'menu1',
            component: Home,
            name: 'Menu1',
            meta: { title: 'menu1', icon: 'example' },
            redirect: '/nested/menu1/menu1-1',
            children: [
                {
                    path: '/nested/menu1/menu1-1',
                    component: Home,
                    name: 'Menu1-1',
                    meta: { title: 'menu1-1' }
                },
                {
                    path: 'menu1-2',
                    component: Home,
                    name: 'Menu1-2',
                    redirect: '/nested/menu1/menu1-2/menu1-2-1',
                    meta: { title: 'menu1-2' },
                    children: [
                        {
                            path: 'menu1-2-1',
                            component: Home,
                            name: 'Menu1-2-1',
                            meta: { title: 'menu1-2-1' }
                        },
                        {
                            path: 'menu1-2-2',
                            component: Home,
                            name: 'Menu1-2-2',
                            meta: { title: 'menu1-2-2' }
                        }
                    ]
                },
                {
                    path: 'menu1-3',
                    component: Home,
                    name: 'Menu1-3',
                    meta: { title: 'menu1-3' }
                }
            ]
        },
        {
            path: 'menu2',
            name: 'Menu2',
            component: Home,
            meta: { title: 'menu2' }
        }
    ]
}
export const constantRoutes: Array<RouteRecordRawExt> = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index.vue')
            }
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/login/index.vue'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [
            {
                path: '/dashboard',
                name: 'Dashboard',
                component: () => import('@/views/dashboard/index.vue'),
                meta: { title: '首页', icon: 'dashboard', affix: true }
            }
        ]
    },
    {
        path: '/:pathMatch(.*)*',
        name: 'Page404',
        component: () => import('@/views/404.vue'),
        hidden: true
    },
    nestedRouter
]

const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes
})

export const asyncRoutes = []

export default router
